import { defineConfig } from "@rsbuild/core";
import { pluginVue } from "@rsbuild/plugin-vue";
import { pluginSass } from "@rsbuild/plugin-sass";
const { codeInspectorPlugin } = require("code-inspector-plugin");
import path from "path";

// 项目名称，用于阿里乾坤子服务配置
const { name } = require("./package.json");

export default defineConfig({
  plugins: [pluginVue(), pluginSass()],
  tools: {
    rspack: {
      plugins: [
        codeInspectorPlugin({
          bundler: "rspack",
        }),
      ],
      output: {
        library: {
          name: `${name}-[name]`,
          type: "umd",
        },
        chunkLoadingGlobal: `webpackJsonp_${name}`,
      },
    },
  },
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "./src"),
    },
  },
  server: {
    proxy: {
      // http://localhost:3000/api -> https://nodejs.org/api
      // http://localhost:3000/api/foo -> https://nodejs.org/api/foo
      "/backend": {
        // target: "https://3fc837b8.r6.cpolar.top",
        target: "http://192.168.1.102:8080",
        pathRewrite: { "^/backend": "" },
      },
    },
  },
});
